package com.all.play.myapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.all.play.myapplication.R;
import com.all.play.myapplication.utils.RegulerUtils;
import com.all.play.myapplication.utils.SharedPreferencesUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 聪明一只哈 on 2018/4/18.
 * Time: 2018/4/18  12:44
 */

public class LoginActivity extends AppCompatActivity {

    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_pass)
    EditText etPass;
    @BindView(R.id.bt_login)
    Button btLogin;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

    }

    @OnClick(R.id.bt_login)
    public void onViewClicked() {
        //1.校验
        String user_name = etName.getText().toString().trim();
        String user_pass = etPass.getText().toString().trim();

        if (!TextUtils.isEmpty(user_name) && !TextUtils.isEmpty(user_pass)) {

            if (RegulerUtils.isMobile(user_name)) {
                //2.本地存储
                SharedPreferencesUtil.saveString(LoginActivity.this,"name",user_name);
                SharedPreferencesUtil.saveString(LoginActivity.this,"pwd",user_pass);

                //3.校验成功后跳转
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                intent.putExtra("name",user_name);
                intent.putExtra("pwd",user_pass);
                startActivity(intent);
                this.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
                finish();


            } else {
                Toast.makeText(LoginActivity.this, "你输入的手机号格式不正确,请重新输入!", Toast.LENGTH_SHORT).show();
            }



        } else {
            Toast.makeText(LoginActivity.this, "您的账号或密码为空,请重新输入!", Toast.LENGTH_SHORT).show();
        }

    }
}
